@fluidframework/azure-service-utils 2.0.0-dev.7.3.0.210328 → 2.0.0-dev.7.3.0.211848

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.
@@ -91,4 +91,4 @@ function generateUser() {
91
91
  return randomUser;
92
92
  }
93
93
  exports.generateUser = generateUser;
94
- //# sourceMappingURL=generateToken.js.map
94
+ //# sourceMappingURL=generateToken.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateToken.cjs","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,yCAA8C;AAC9C,+BAAkC;AAIlC;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,aAAa,CAC5B,QAAgB,EAChB,GAAW,EACX,MAAmB,EACnB,UAAmB,EACnB,IAAY,EACZ,WAAmB,EAAE,GAAG,EAAE;AAC1B,8CAA8C;AAC9C,yDAAyD;AACzD,MAAc,KAAK;IAEnB,IAAI,SAAS,GAAG,IAAI,IAAI,YAAY,EAAE,CAAC;IACvC,IAAI,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,SAAS,CAAC,EAAE,KAAK,SAAS,EAAE;QACtD,SAAS,GAAG,YAAY,EAAE,CAAC;KAC3B;IAED,0BAA0B;IAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IAE1C,MAAM,MAAM,GAAmC;QAC9C,UAAU,EAAE,UAAU,IAAI,EAAE;QAC5B,MAAM;QACN,QAAQ;QACR,IAAI,EAAE,SAAS;QACf,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG,GAAG,QAAQ;QACnB,GAAG;QACH,sGAAsG;QACtG,GAAG,EAAE,IAAA,SAAI,GAAE;KACX,CAAC;IAEF,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAE9B,OAAO,gBAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI;IAC5B,yBAAyB;IACzB,2CAA2C;IAC3C,IAAI,EACJ,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAC5C,MAAM,EACN,OAAO,CACP,CAAC;AACH,CAAC;AAzCD,sCAyCC;AAED;;;GAGG;AACH,SAAgB,YAAY;IAC3B,MAAM,UAAU,GAAG;QAClB,sGAAsG;QACtG,EAAE,EAAE,IAAA,SAAI,GAAE;QACV,sGAAsG;QACtG,IAAI,EAAE,IAAA,SAAI,GAAE;KACZ,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC;AATD,oCASC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { KJUR as jsrsasign } from \"jsrsasign\";\nimport { v4 as uuid } from \"uuid\";\n\nimport type { ITokenClaims, IUser, ScopeType } from \"@fluidframework/protocol-definitions\";\n\n/**\n * IMPORTANT: This function is duplicated in ./packages/runtime/test-runtime-utils/src/generateToken.ts. There is no\n * need for different implementations, so they should be kept in sync if changes are needed.\n *\n * The reason they are duplicated is because we don't want the core Fluid libraries depending on the Azure libraries\n * (enforced by layer-check), but both need to expose this function. The test-runtime-utils library is a test lib, which\n * layer-check (correctly) reuires only be used as a dev dependency. But in the azure case, we want the function\n * exported, so it needs to be sourced from either the package itself or a non-dev dependency.\n *\n * The previous solution to this was to import the function from azure-service-utils into test-runtime-utils, but that\n * no longer works because the azure packages are in a separate release group.\n *\n * If a token needs to be generated on the client side, you should re-use this function. If you need service-side token\n * generation, you should use the function available in the server-services-client package in order to avoid\n * interdependencies between service and client packages.\n */\n\n/**\n * Generates a {@link https://en.wikipedia.org/wiki/JSON_Web_Token | JSON Web Token} (JWT)\n * to authorize access to a Routerlicious-based Fluid service.\n *\n * @remarks Note: this function uses a browser friendly auth library\n * ({@link https://www.npmjs.com/package/jsrsasign | jsrsasign}) and may only be used in client (browser) context.\n * It is **not** Node.js-compatible.\n *\n * @param tenantId - See {@link @fluidframework/protocol-definitions#ITokenClaims.tenantId}\n * @param key - API key to authenticate user. Must be {@link https://en.wikipedia.org/wiki/UTF-8 | UTF-8}-encoded.\n * @param scopes - See {@link @fluidframework/protocol-definitions#ITokenClaims.scopes}\n * @param documentId - See {@link @fluidframework/protocol-definitions#ITokenClaims.documentId}.\n * If not specified, the token will not be associated with a document, and an empty string will be used.\n * @param user - User with whom generated tokens will be associated.\n * If not specified, the token will not be associated with a user, and a randomly generated mock user will be\n * used instead.\n * See {@link @fluidframework/protocol-definitions#ITokenClaims.user}\n * @param lifetime - Used to generate the {@link @fluidframework/protocol-definitions#ITokenClaims.exp | expiration}.\n * Expiration = now + lifetime.\n * Expressed in seconds.\n * Default: 3600 (1 hour).\n * @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.\n * Default: `1.0`.\n *\n * @public\n */\nexport function generateToken(\n\ttenantId: string,\n\tkey: string,\n\tscopes: ScopeType[],\n\tdocumentId?: string,\n\tuser?: IUser,\n\tlifetime: number = 60 * 60,\n\t// Naming intended to match `ITokenClaims.ver`\n\t// eslint-disable-next-line unicorn/prevent-abbreviations\n\tver: string = \"1.0\",\n): string {\n\tlet userClaim = user ?? generateUser();\n\tif (userClaim.id === \"\" || userClaim.id === undefined) {\n\t\tuserClaim = generateUser();\n\t}\n\n\t// Current time in seconds\n\tconst now = Math.round(Date.now() / 1000);\n\n\tconst claims: ITokenClaims & { jti: string } = {\n\t\tdocumentId: documentId ?? \"\",\n\t\tscopes,\n\t\ttenantId,\n\t\tuser: userClaim,\n\t\tiat: now,\n\t\texp: now + lifetime,\n\t\tver,\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tjti: uuid(),\n\t};\n\n\tconst utf8Key = { utf8: key };\n\n\treturn jsrsasign.jws.JWS.sign(\n\t\t// External API uses null\n\t\t// eslint-disable-next-line unicorn/no-null\n\t\tnull,\n\t\tJSON.stringify({ alg: \"HS256\", typ: \"JWT\" }),\n\t\tclaims,\n\t\tutf8Key,\n\t);\n}\n\n/**\n * Generates an arbitrary (\"random\") {@link @fluidframework/protocol-definitions#IUser} by generating a\n * random UUID for its {@link @fluidframework/protocol-definitions#IUser.id} and `name` properties.\n */\nexport function generateUser(): IUser {\n\tconst randomUser = {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tid: uuid(),\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tname: uuid(),\n\t};\n\n\treturn randomUser;\n}\n"]}
@@ -7,6 +7,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.generateToken = exports.ScopeType = void 0;
8
8
  var protocol_definitions_1 = require("@fluidframework/protocol-definitions");
9
9
  Object.defineProperty(exports, "ScopeType", { enumerable: true, get: function () { return protocol_definitions_1.ScopeType; } });
10
- var generateToken_1 = require("./generateToken");
10
+ var generateToken_1 = require("./generateToken.cjs");
11
11
  Object.defineProperty(exports, "generateToken", { enumerable: true, get: function () { return generateToken_1.generateToken; } });
12
- //# sourceMappingURL=index.js.map
12
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAeH,6EAAiE;AAAxD,iHAAA,SAAS,OAAA;AAClB,qDAAgD;AAAvC,8GAAA,aAAa,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * A set of helper utilities for building backend APIs for use with\n * {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.\n *\n * @remarks\n * Note that this library's primary entry-point ({@link generateToken}) is only intended\n * to be run in a browser context.\n * It is **not** Node.js-compatible.\n *\n * @packageDocumentation\n */\n\nexport type { IUser } from \"@fluidframework/protocol-definitions\";\nexport { ScopeType } from \"@fluidframework/protocol-definitions\";\nexport { generateToken } from \"./generateToken\";\n"]}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.38.0"
8
+ "packageVersion": "7.38.3"
9
9
  }
10
10
  ]
11
11
  }
@@ -1,7 +1,3 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
1
  import { KJUR as jsrsasign } from "jsrsasign";
6
2
  import { v4 as uuid } from "uuid";
7
3
  /**
@@ -86,4 +82,4 @@ export function generateUser() {
86
82
  };
87
83
  return randomUser;
88
84
  }
89
- //# sourceMappingURL=generateToken.js.map
85
+ //# sourceMappingURL=generateToken.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateToken.mjs","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":"OAIO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,WAAW;OACtC,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM;AAIjC;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,aAAa,CAC5B,QAAgB,EAChB,GAAW,EACX,MAAmB,EACnB,UAAmB,EACnB,IAAY,EACZ,WAAmB,EAAE,GAAG,EAAE;AAC1B,8CAA8C;AAC9C,yDAAyD;AACzD,MAAc,KAAK;IAEnB,IAAI,SAAS,GAAG,IAAI,IAAI,YAAY,EAAE,CAAC;IACvC,IAAI,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,SAAS,CAAC,EAAE,KAAK,SAAS,EAAE;QACtD,SAAS,GAAG,YAAY,EAAE,CAAC;KAC3B;IAED,0BAA0B;IAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IAE1C,MAAM,MAAM,GAAmC;QAC9C,UAAU,EAAE,UAAU,IAAI,EAAE;QAC5B,MAAM;QACN,QAAQ;QACR,IAAI,EAAE,SAAS;QACf,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG,GAAG,QAAQ;QACnB,GAAG;QACH,sGAAsG;QACtG,GAAG,EAAE,IAAI,EAAE;KACX,CAAC;IAEF,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAE9B,OAAO,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI;IAC5B,yBAAyB;IACzB,2CAA2C;IAC3C,IAAI,EACJ,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAC5C,MAAM,EACN,OAAO,CACP,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY;IAC3B,MAAM,UAAU,GAAG;QAClB,sGAAsG;QACtG,EAAE,EAAE,IAAI,EAAE;QACV,sGAAsG;QACtG,IAAI,EAAE,IAAI,EAAE;KACZ,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { KJUR as jsrsasign } from \"jsrsasign\";\nimport { v4 as uuid } from \"uuid\";\n\nimport type { ITokenClaims, IUser, ScopeType } from \"@fluidframework/protocol-definitions\";\n\n/**\n * IMPORTANT: This function is duplicated in ./packages/runtime/test-runtime-utils/src/generateToken.ts. There is no\n * need for different implementations, so they should be kept in sync if changes are needed.\n *\n * The reason they are duplicated is because we don't want the core Fluid libraries depending on the Azure libraries\n * (enforced by layer-check), but both need to expose this function. The test-runtime-utils library is a test lib, which\n * layer-check (correctly) reuires only be used as a dev dependency. But in the azure case, we want the function\n * exported, so it needs to be sourced from either the package itself or a non-dev dependency.\n *\n * The previous solution to this was to import the function from azure-service-utils into test-runtime-utils, but that\n * no longer works because the azure packages are in a separate release group.\n *\n * If a token needs to be generated on the client side, you should re-use this function. If you need service-side token\n * generation, you should use the function available in the server-services-client package in order to avoid\n * interdependencies between service and client packages.\n */\n\n/**\n * Generates a {@link https://en.wikipedia.org/wiki/JSON_Web_Token | JSON Web Token} (JWT)\n * to authorize access to a Routerlicious-based Fluid service.\n *\n * @remarks Note: this function uses a browser friendly auth library\n * ({@link https://www.npmjs.com/package/jsrsasign | jsrsasign}) and may only be used in client (browser) context.\n * It is **not** Node.js-compatible.\n *\n * @param tenantId - See {@link @fluidframework/protocol-definitions#ITokenClaims.tenantId}\n * @param key - API key to authenticate user. Must be {@link https://en.wikipedia.org/wiki/UTF-8 | UTF-8}-encoded.\n * @param scopes - See {@link @fluidframework/protocol-definitions#ITokenClaims.scopes}\n * @param documentId - See {@link @fluidframework/protocol-definitions#ITokenClaims.documentId}.\n * If not specified, the token will not be associated with a document, and an empty string will be used.\n * @param user - User with whom generated tokens will be associated.\n * If not specified, the token will not be associated with a user, and a randomly generated mock user will be\n * used instead.\n * See {@link @fluidframework/protocol-definitions#ITokenClaims.user}\n * @param lifetime - Used to generate the {@link @fluidframework/protocol-definitions#ITokenClaims.exp | expiration}.\n * Expiration = now + lifetime.\n * Expressed in seconds.\n * Default: 3600 (1 hour).\n * @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.\n * Default: `1.0`.\n *\n * @public\n */\nexport function generateToken(\n\ttenantId: string,\n\tkey: string,\n\tscopes: ScopeType[],\n\tdocumentId?: string,\n\tuser?: IUser,\n\tlifetime: number = 60 * 60,\n\t// Naming intended to match `ITokenClaims.ver`\n\t// eslint-disable-next-line unicorn/prevent-abbreviations\n\tver: string = \"1.0\",\n): string {\n\tlet userClaim = user ?? generateUser();\n\tif (userClaim.id === \"\" || userClaim.id === undefined) {\n\t\tuserClaim = generateUser();\n\t}\n\n\t// Current time in seconds\n\tconst now = Math.round(Date.now() / 1000);\n\n\tconst claims: ITokenClaims & { jti: string } = {\n\t\tdocumentId: documentId ?? \"\",\n\t\tscopes,\n\t\ttenantId,\n\t\tuser: userClaim,\n\t\tiat: now,\n\t\texp: now + lifetime,\n\t\tver,\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tjti: uuid(),\n\t};\n\n\tconst utf8Key = { utf8: key };\n\n\treturn jsrsasign.jws.JWS.sign(\n\t\t// External API uses null\n\t\t// eslint-disable-next-line unicorn/no-null\n\t\tnull,\n\t\tJSON.stringify({ alg: \"HS256\", typ: \"JWT\" }),\n\t\tclaims,\n\t\tutf8Key,\n\t);\n}\n\n/**\n * Generates an arbitrary (\"random\") {@link @fluidframework/protocol-definitions#IUser} by generating a\n * random UUID for its {@link @fluidframework/protocol-definitions#IUser.id} and `name` properties.\n */\nexport function generateUser(): IUser {\n\tconst randomUser = {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tid: uuid(),\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tname: uuid(),\n\t};\n\n\treturn randomUser;\n}\n"]}
@@ -3,5 +3,5 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  export { ScopeType } from "@fluidframework/protocol-definitions";
6
- export { generateToken } from "./generateToken";
7
- //# sourceMappingURL=index.js.map
6
+ export { generateToken } from "./generateToken.mjs";
7
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAeI,EAAE,SAAS,EAAE,MAAM,sCAAsC;OACzD,EAAE,aAAa,EAAE","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * A set of helper utilities for building backend APIs for use with\n * {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.\n *\n * @remarks\n * Note that this library's primary entry-point ({@link generateToken}) is only intended\n * to be run in a browser context.\n * It is **not** Node.js-compatible.\n *\n * @packageDocumentation\n */\n\nexport type { IUser } from \"@fluidframework/protocol-definitions\";\nexport { ScopeType } from \"@fluidframework/protocol-definitions\";\nexport { generateToken } from \"./generateToken\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/azure-service-utils",
3
- "version": "2.0.0-dev.7.3.0.210328",
3
+ "version": "2.0.0-dev.7.3.0.211848",
4
4
  "description": "Helper service-side utilities for connecting to Azure Fluid Relay service",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -15,16 +15,16 @@
15
15
  ".": {
16
16
  "import": {
17
17
  "types": "./lib/index.d.ts",
18
- "default": "./lib/index.js"
18
+ "default": "./lib/index.mjs"
19
19
  },
20
20
  "require": {
21
21
  "types": "./dist/index.d.ts",
22
- "default": "./dist/index.js"
22
+ "default": "./dist/index.cjs"
23
23
  }
24
24
  }
25
25
  },
26
- "main": "dist/index.js",
27
- "module": "lib/index.js",
26
+ "main": "dist/index.cjs",
27
+ "module": "lib/index.mjs",
28
28
  "types": "dist/index.d.ts",
29
29
  "dependencies": {
30
30
  "@fluidframework/protocol-definitions": "^3.0.0",
@@ -32,18 +32,19 @@
32
32
  "uuid": "^9.0.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@fluid-tools/build-cli": "^0.27.0",
35
+ "@fluid-tools/build-cli": "0.28.0-210888",
36
36
  "@fluidframework/azure-service-utils-previous": "npm:@fluidframework/azure-service-utils@2.0.0-internal.7.2.0",
37
37
  "@fluidframework/build-common": "^2.0.3",
38
- "@fluidframework/build-tools": "^0.27.0",
38
+ "@fluidframework/build-tools": "0.28.0-210888",
39
39
  "@fluidframework/eslint-config-fluid": "^3.1.0",
40
- "@microsoft/api-extractor": "^7.37.0",
40
+ "@microsoft/api-extractor": "^7.38.3",
41
41
  "@types/jsrsasign": "^8.0.8",
42
42
  "copyfiles": "^2.4.1",
43
43
  "eslint": "~8.50.0",
44
44
  "eslint-config-prettier": "~9.0.0",
45
45
  "prettier": "~3.0.3",
46
46
  "rimraf": "^4.4.0",
47
+ "tsc-multi": "^1.1.0",
47
48
  "typescript": "~5.1.6"
48
49
  },
49
50
  "fluidBuild": {
@@ -69,10 +70,10 @@
69
70
  "build:commonjs": "fluid-build . --task commonjs",
70
71
  "build:compile": "fluid-build . --task compile",
71
72
  "build:docs": "fluid-build . --task api",
72
- "build:esnext": "tsc --project ./tsconfig.esnext.json",
73
- "build:test": "tsc --project ./src/test/tsconfig.json",
73
+ "build:esnext": "tsc-multi --config ../../../common/build/build-common/tsc-multi.esm.json",
74
+ "build:test": "tsc-multi --config ./tsc-multi.test.json",
74
75
  "ci:build:docs": "api-extractor run",
75
- "clean": "rimraf --glob dist lib \"*.tsbuildinfo\" \"*.build.log\" _api-extractor-temp",
76
+ "clean": "rimraf --glob dist lib \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp",
76
77
  "eslint": "eslint --format stylish src",
77
78
  "eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
78
79
  "format": "npm run prettier:fix",
@@ -81,7 +82,7 @@
81
82
  "prettier": "prettier --check . --ignore-path ../../../.prettierignore",
82
83
  "prettier:fix": "prettier --write . --ignore-path ../../../.prettierignore",
83
84
  "test": "echo \"Error: no test specified\" && exit 1",
84
- "tsc": "tsc",
85
+ "tsc": "tsc-multi --config ../../../common/build/build-common/tsc-multi.cjs.json",
85
86
  "typetests:gen": "fluid-type-test-generator",
86
87
  "typetests:prepare": "flub typetests --dir . --reset --previous --normalize"
87
88
  }
@@ -0,0 +1,4 @@
1
+ {
2
+ "targets": [{ "extname": ".cjs", "module": "CommonJS", "moduleResolution": "Node10" }],
3
+ "projects": ["./tsconfig.json", "./src/test/tsconfig.json"]
4
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateToken.js","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,yCAA8C;AAC9C,+BAAkC;AAIlC;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,aAAa,CAC5B,QAAgB,EAChB,GAAW,EACX,MAAmB,EACnB,UAAmB,EACnB,IAAY,EACZ,WAAmB,EAAE,GAAG,EAAE;AAC1B,8CAA8C;AAC9C,yDAAyD;AACzD,MAAc,KAAK;IAEnB,IAAI,SAAS,GAAG,IAAI,IAAI,YAAY,EAAE,CAAC;IACvC,IAAI,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,SAAS,CAAC,EAAE,KAAK,SAAS,EAAE;QACtD,SAAS,GAAG,YAAY,EAAE,CAAC;KAC3B;IAED,0BAA0B;IAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IAE1C,MAAM,MAAM,GAAmC;QAC9C,UAAU,EAAE,UAAU,IAAI,EAAE;QAC5B,MAAM;QACN,QAAQ;QACR,IAAI,EAAE,SAAS;QACf,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG,GAAG,QAAQ;QACnB,GAAG;QACH,sGAAsG;QACtG,GAAG,EAAE,IAAA,SAAI,GAAE;KACX,CAAC;IAEF,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAE9B,OAAO,gBAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI;IAC5B,yBAAyB;IACzB,2CAA2C;IAC3C,IAAI,EACJ,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAC5C,MAAM,EACN,OAAO,CACP,CAAC;AACH,CAAC;AAzCD,sCAyCC;AAED;;;GAGG;AACH,SAAgB,YAAY;IAC3B,MAAM,UAAU,GAAG;QAClB,sGAAsG;QACtG,EAAE,EAAE,IAAA,SAAI,GAAE;QACV,sGAAsG;QACtG,IAAI,EAAE,IAAA,SAAI,GAAE;KACZ,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC;AATD,oCASC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { KJUR as jsrsasign } from \"jsrsasign\";\nimport { v4 as uuid } from \"uuid\";\n\nimport type { ITokenClaims, IUser, ScopeType } from \"@fluidframework/protocol-definitions\";\n\n/**\n * IMPORTANT: This function is duplicated in ./packages/runtime/test-runtime-utils/src/generateToken.ts. There is no\n * need for different implementations, so they should be kept in sync if changes are needed.\n *\n * The reason they are duplicated is because we don't want the core Fluid libraries depending on the Azure libraries\n * (enforced by layer-check), but both need to expose this function. The test-runtime-utils library is a test lib, which\n * layer-check (correctly) reuires only be used as a dev dependency. But in the azure case, we want the function\n * exported, so it needs to be sourced from either the package itself or a non-dev dependency.\n *\n * The previous solution to this was to import the function from azure-service-utils into test-runtime-utils, but that\n * no longer works because the azure packages are in a separate release group.\n *\n * If a token needs to be generated on the client side, you should re-use this function. If you need service-side token\n * generation, you should use the function available in the server-services-client package in order to avoid\n * interdependencies between service and client packages.\n */\n\n/**\n * Generates a {@link https://en.wikipedia.org/wiki/JSON_Web_Token | JSON Web Token} (JWT)\n * to authorize access to a Routerlicious-based Fluid service.\n *\n * @remarks Note: this function uses a browser friendly auth library\n * ({@link https://www.npmjs.com/package/jsrsasign | jsrsasign}) and may only be used in client (browser) context.\n * It is **not** Node.js-compatible.\n *\n * @param tenantId - See {@link @fluidframework/protocol-definitions#ITokenClaims.tenantId}\n * @param key - API key to authenticate user. Must be {@link https://en.wikipedia.org/wiki/UTF-8 | UTF-8}-encoded.\n * @param scopes - See {@link @fluidframework/protocol-definitions#ITokenClaims.scopes}\n * @param documentId - See {@link @fluidframework/protocol-definitions#ITokenClaims.documentId}.\n * If not specified, the token will not be associated with a document, and an empty string will be used.\n * @param user - User with whom generated tokens will be associated.\n * If not specified, the token will not be associated with a user, and a randomly generated mock user will be\n * used instead.\n * See {@link @fluidframework/protocol-definitions#ITokenClaims.user}\n * @param lifetime - Used to generate the {@link @fluidframework/protocol-definitions#ITokenClaims.exp | expiration}.\n * Expiration = now + lifetime.\n * Expressed in seconds.\n * Default: 3600 (1 hour).\n * @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.\n * Default: `1.0`.\n *\n * @public\n */\nexport function generateToken(\n\ttenantId: string,\n\tkey: string,\n\tscopes: ScopeType[],\n\tdocumentId?: string,\n\tuser?: IUser,\n\tlifetime: number = 60 * 60,\n\t// Naming intended to match `ITokenClaims.ver`\n\t// eslint-disable-next-line unicorn/prevent-abbreviations\n\tver: string = \"1.0\",\n): string {\n\tlet userClaim = user ?? generateUser();\n\tif (userClaim.id === \"\" || userClaim.id === undefined) {\n\t\tuserClaim = generateUser();\n\t}\n\n\t// Current time in seconds\n\tconst now = Math.round(Date.now() / 1000);\n\n\tconst claims: ITokenClaims & { jti: string } = {\n\t\tdocumentId: documentId ?? \"\",\n\t\tscopes,\n\t\ttenantId,\n\t\tuser: userClaim,\n\t\tiat: now,\n\t\texp: now + lifetime,\n\t\tver,\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tjti: uuid(),\n\t};\n\n\tconst utf8Key = { utf8: key };\n\n\treturn jsrsasign.jws.JWS.sign(\n\t\t// External API uses null\n\t\t// eslint-disable-next-line unicorn/no-null\n\t\tnull,\n\t\tJSON.stringify({ alg: \"HS256\", typ: \"JWT\" }),\n\t\tclaims,\n\t\tutf8Key,\n\t);\n}\n\n/**\n * Generates an arbitrary (\"random\") {@link @fluidframework/protocol-definitions#IUser} by generating a\n * random UUID for its {@link @fluidframework/protocol-definitions#IUser.id} and `name` properties.\n */\nexport function generateUser(): IUser {\n\tconst randomUser = {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tid: uuid(),\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tname: uuid(),\n\t};\n\n\treturn randomUser;\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;;;GAGG;;;AAeH,6EAAiE;AAAxD,iHAAA,SAAS,OAAA;AAClB,iDAAgD;AAAvC,8GAAA,aAAa,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * A set of helper utilities for building backend APIs for use with\n * {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.\n *\n * @remarks\n * Note that this library's primary entry-point ({@link generateToken}) is only intended\n * to be run in a browser context.\n * It is **not** Node.js-compatible.\n *\n * @packageDocumentation\n */\n\nexport type { IUser } from \"@fluidframework/protocol-definitions\";\nexport { ScopeType } from \"@fluidframework/protocol-definitions\";\nexport { generateToken } from \"./generateToken\";\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateToken.js","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAIlC;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,aAAa,CAC5B,QAAgB,EAChB,GAAW,EACX,MAAmB,EACnB,UAAmB,EACnB,IAAY,EACZ,WAAmB,EAAE,GAAG,EAAE;AAC1B,8CAA8C;AAC9C,yDAAyD;AACzD,MAAc,KAAK;IAEnB,IAAI,SAAS,GAAG,IAAI,IAAI,YAAY,EAAE,CAAC;IACvC,IAAI,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,SAAS,CAAC,EAAE,KAAK,SAAS,EAAE;QACtD,SAAS,GAAG,YAAY,EAAE,CAAC;KAC3B;IAED,0BAA0B;IAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IAE1C,MAAM,MAAM,GAAmC;QAC9C,UAAU,EAAE,UAAU,IAAI,EAAE;QAC5B,MAAM;QACN,QAAQ;QACR,IAAI,EAAE,SAAS;QACf,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG,GAAG,QAAQ;QACnB,GAAG;QACH,sGAAsG;QACtG,GAAG,EAAE,IAAI,EAAE;KACX,CAAC;IAEF,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAE9B,OAAO,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI;IAC5B,yBAAyB;IACzB,2CAA2C;IAC3C,IAAI,EACJ,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAC5C,MAAM,EACN,OAAO,CACP,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY;IAC3B,MAAM,UAAU,GAAG;QAClB,sGAAsG;QACtG,EAAE,EAAE,IAAI,EAAE;QACV,sGAAsG;QACtG,IAAI,EAAE,IAAI,EAAE;KACZ,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { KJUR as jsrsasign } from \"jsrsasign\";\nimport { v4 as uuid } from \"uuid\";\n\nimport type { ITokenClaims, IUser, ScopeType } from \"@fluidframework/protocol-definitions\";\n\n/**\n * IMPORTANT: This function is duplicated in ./packages/runtime/test-runtime-utils/src/generateToken.ts. There is no\n * need for different implementations, so they should be kept in sync if changes are needed.\n *\n * The reason they are duplicated is because we don't want the core Fluid libraries depending on the Azure libraries\n * (enforced by layer-check), but both need to expose this function. The test-runtime-utils library is a test lib, which\n * layer-check (correctly) reuires only be used as a dev dependency. But in the azure case, we want the function\n * exported, so it needs to be sourced from either the package itself or a non-dev dependency.\n *\n * The previous solution to this was to import the function from azure-service-utils into test-runtime-utils, but that\n * no longer works because the azure packages are in a separate release group.\n *\n * If a token needs to be generated on the client side, you should re-use this function. If you need service-side token\n * generation, you should use the function available in the server-services-client package in order to avoid\n * interdependencies between service and client packages.\n */\n\n/**\n * Generates a {@link https://en.wikipedia.org/wiki/JSON_Web_Token | JSON Web Token} (JWT)\n * to authorize access to a Routerlicious-based Fluid service.\n *\n * @remarks Note: this function uses a browser friendly auth library\n * ({@link https://www.npmjs.com/package/jsrsasign | jsrsasign}) and may only be used in client (browser) context.\n * It is **not** Node.js-compatible.\n *\n * @param tenantId - See {@link @fluidframework/protocol-definitions#ITokenClaims.tenantId}\n * @param key - API key to authenticate user. Must be {@link https://en.wikipedia.org/wiki/UTF-8 | UTF-8}-encoded.\n * @param scopes - See {@link @fluidframework/protocol-definitions#ITokenClaims.scopes}\n * @param documentId - See {@link @fluidframework/protocol-definitions#ITokenClaims.documentId}.\n * If not specified, the token will not be associated with a document, and an empty string will be used.\n * @param user - User with whom generated tokens will be associated.\n * If not specified, the token will not be associated with a user, and a randomly generated mock user will be\n * used instead.\n * See {@link @fluidframework/protocol-definitions#ITokenClaims.user}\n * @param lifetime - Used to generate the {@link @fluidframework/protocol-definitions#ITokenClaims.exp | expiration}.\n * Expiration = now + lifetime.\n * Expressed in seconds.\n * Default: 3600 (1 hour).\n * @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.\n * Default: `1.0`.\n *\n * @public\n */\nexport function generateToken(\n\ttenantId: string,\n\tkey: string,\n\tscopes: ScopeType[],\n\tdocumentId?: string,\n\tuser?: IUser,\n\tlifetime: number = 60 * 60,\n\t// Naming intended to match `ITokenClaims.ver`\n\t// eslint-disable-next-line unicorn/prevent-abbreviations\n\tver: string = \"1.0\",\n): string {\n\tlet userClaim = user ?? generateUser();\n\tif (userClaim.id === \"\" || userClaim.id === undefined) {\n\t\tuserClaim = generateUser();\n\t}\n\n\t// Current time in seconds\n\tconst now = Math.round(Date.now() / 1000);\n\n\tconst claims: ITokenClaims & { jti: string } = {\n\t\tdocumentId: documentId ?? \"\",\n\t\tscopes,\n\t\ttenantId,\n\t\tuser: userClaim,\n\t\tiat: now,\n\t\texp: now + lifetime,\n\t\tver,\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tjti: uuid(),\n\t};\n\n\tconst utf8Key = { utf8: key };\n\n\treturn jsrsasign.jws.JWS.sign(\n\t\t// External API uses null\n\t\t// eslint-disable-next-line unicorn/no-null\n\t\tnull,\n\t\tJSON.stringify({ alg: \"HS256\", typ: \"JWT\" }),\n\t\tclaims,\n\t\tutf8Key,\n\t);\n}\n\n/**\n * Generates an arbitrary (\"random\") {@link @fluidframework/protocol-definitions#IUser} by generating a\n * random UUID for its {@link @fluidframework/protocol-definitions#IUser.id} and `name` properties.\n */\nexport function generateUser(): IUser {\n\tconst randomUser = {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tid: uuid(),\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tname: uuid(),\n\t};\n\n\treturn randomUser;\n}\n"]}
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAeH,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * A set of helper utilities for building backend APIs for use with\n * {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.\n *\n * @remarks\n * Note that this library's primary entry-point ({@link generateToken}) is only intended\n * to be run in a browser context.\n * It is **not** Node.js-compatible.\n *\n * @packageDocumentation\n */\n\nexport type { IUser } from \"@fluidframework/protocol-definitions\";\nexport { ScopeType } from \"@fluidframework/protocol-definitions\";\nexport { generateToken } from \"./generateToken\";\n"]}
@@ -1,6 +0,0 @@
1
- {
2
- "extends": ["./tsconfig.json", "../../../common/build/build-common/tsconfig.esm.json"],
3
- "compilerOptions": {
4
- "outDir": "./lib",
5
- },
6
- }